{include file="header.html"}
<body class="gr">

<div class="navBar">
	<a class="left" href="wap.php?app=member&act=order&integral_order=1"><i class="return"></i></a>
	<div class="titleView">订单详情</div>
	{if $data->shipping_company!=''}<a class="right" href="wap.php?app=member&act=order_express&id={$data->id}">物流</a>{/if}
</div>

<div class="member-order-detail main-top">
	<ul class="groupView">
		<li>
			<div class="top">{$data->status}</div>
			<div class="address">
				<div>
					<span>收货人: {$data->name}　{$data->mobile}</span>
					<span>{$data->province}{if $data->province!=$data->city} {$data->city}{/if} {$data->district} {$data->address}</span>
				</div>
			</div>
		</li>
		
		<li>
			<ul>
				{foreach from=$data->goods name=g item=g}
				<li class="ge-bottom ge-light">
					<div class="gview" price="{$g->price}" quantity="{$g->quantity}">
						<a href="wap.php?app=goods&act=detail&goods_id={$g->goods_id}" class="pic" style="background-image:url({$g->goods_pic});"></a>
						<a href="wap.php?app=goods&act=detail&goods_id={$g->goods_id}" class="name right"><span class="price">{if !isset($integral_order)}￥{number_format($g->price,2)}{else}{$g->integral}积分{/if}</span>{$g->goods_name}</a>
						{if !isset($integral_order)}<div class="spec"><span>×{$g->quantity}</span><div>规格：{$g->spec}</div></div>
						{else}<div class="spec"><div>规格：{$g->spec}</div></div>{/if}
						{if !isset($integral_order)}
						{if $data->status==3 || $data->status==4}
						{if $g->comment_time==0}
						<div class="comment"><a href="wap.php?tpl=member.order_comment&order_id={$data->id}&goods_id={$g->goods_id}&goods_name={$g->goods_name}&goods_pic={$g->goods_pic}"><span>评价</span></a></div>
						{else}
						<div class="comment"><font>已评价</font></div>
						{/if}
						{/if}
						{/if}
					</div>
				</li>
				{/foreach}
			</ul>
			<div class="view">
				<div class="trans"><strong>{if $data->shipping_price>0}￥{number_format($data->shipping_price,2)}{else}免邮{/if}</strong><span>运费</span></div>
				{if !isset($integral_order)}
				<div class="total"><strong>￥{number_format($data->total_price,2)}</strong><span>实付款(含运费)</span></div>
				{else}
				<div class="total"><strong>{intval($data->total_price)}积分</strong><span>总积分</span></div>
					{if $data->status == 1 }
					<div class="order_cancel">
						<span cancel_id="{$data->id}" status="{$data->status}">取消</span>
					</div>
					{/if}
				{/if}
			</div>
			<!--
			<div class="opr ge-top ge-light">
				<a class="im ge-right ge-light" href="javascript:void(0)" member_id="yanglanzi"><div><span>联系客服</span></div></a>
				<a class="tel" href="tel://{$data->shop_mobile}"><div><span>拨打电话</span></div></a>
			</div>
			-->
		</li>
		
		{if $data->shipping_number!=''}
		<li>
			<div class="info">
				<div>物流公司: {$data->shipping_company}</div>
				<div>物流单号: {$data->shipping_number}</div>
			</div>
		</li>
		{/if}
		
		<li>
			<div class="info">
				<div>订单状态: <span class="status status{$data->status}"><font>{$data->status}</font>{if $data->status>0 && $data->ask_refund_time>0} <span>(退货退款中)</span>{/if}</span></div>
				<div>订单编号: {$data->order_sn}</div>
				<div>创建时间: {$data->add_time_str}</div>
				{if !isset($integral_order) && $data->pay_time>0}<div>付款时间: {$data->pay_time_str}</div>{/if}
				{if $data->shipping_time>0}<div>发货时间: {$data->shipping_time_str}</div>{/if}
				{if $data->shouhuo_time>0}<div>成交时间: {$data->shouhuo_time_str}</div>{/if}
			</div>
		</li>
	</ul>
	
	{if (!isset($integral_order) && $data->status>=0) || (isset($integral_order) && $data->status==2)}
	<div class="bottomView" mid="{$data->id}">
		<div class="ge-top ge-light">
			{if $data->status==0}
			<a class="pay" href="javascript:void(0)" pay_method="{$data->pay_method}"><span>立即支付</span></a>
			<a class="cancel" href="javascript:void(0)"><span>取消订单</span></a>
			<form class="pay_form" action="wap.php?app=member&act=order_pay" method="post">
			<input type="hidden" name="re_order_sn" value="" />
			<input type="hidden" name="order_sn" value="{$data->order_sn}" />
			<input type="hidden" name="price" value="{$data->total_price}" />
			<input type="hidden" name="body" value="商富商城-订单" />
			</form>
			<form class="cancel_form" action="api.php?app=member&act=order_cancel" method="post">
			<input type="hidden" name="gourl" value="wap.php?app=member&act=order_detail&id={$data->id}" />
			<input type="hidden" name="id" value="{$data->id}" />
			</form>
			{/if}
			{if $data->status==1}
			{if !isset($integral_order) && $data->ask_refund_time==0}
			<a class="refund" href="javascript:void(0)" total_price="{$data->total_price}" status="{$data->status}"><span>我要退款</span></a>
			{/if}
			<a class="ask" href="javascript:void(0)"><span>提醒商家发货</span></a>
			<form class="ask_form" action="api.php?app=order&act=ask_shipping" method="post">
			<input type="hidden" name="goalert" value="已提醒商家尽快发货，请耐心等待" />
			<input type="hidden" name="gourl" value="wap.php?app=member&act=order_detail&id={$data->id}" />
			<input type="hidden" name="order_id" value="{$data->id}" />
			</form>
			{/if}
			{if $data->status==2}
			<a class="ok" href="javascript:void(0)"><span>确认收货</span></a>
			{if !isset($integral_order) && $data->delay_shouhuo_time==0}
			<a class="delay" href="javascript:void(0)"><span>延迟收货</span></a>
			{/if}
			{if !isset($integral_order) && $data->ask_refund_time==0}
			<a class="refund" href="javascript:void(0)" total_price="{$data->total_price}" status="{$data->status}"><span>我要退款</span></a>
			{/if}
			<form class="delay_form" action="api.php?app=order&act=delay_shouhuo" method="post">
			<input type="hidden" name="goalert" value="已执行延迟收货操作" />
			<input type="hidden" name="gourl" value="wap.php?app=member&act=order_detail&id={$data->id}" />
			<input type="hidden" name="order_id" value="{$data->id}" />
			</form>
			{/if}
			{if $data->status>=3}
			<a class="again" href="javascript:void(0)"><span>再次购买</span></a>
			<form class="again_form" action="api.php?app=cart&act=add_cart" method="post">
			<textarea style="display:none;">{json_encode($data->goods)}</textarea>
			<input type="hidden" name="gourl" value="wap.php?app=coffee_cart&act=index" />
			<input type="hidden" name="goods" class="goods" value="" />
			</form>
			{/if}
		</div>
	</div>
	{/if}
</div>

{include file="footer.html"}
<script>
function statusName(status){
	var name = '';
	switch(status*1){
		case -3:name = '已退货';break;
		case -2:name = '已退款';break;
		case -1:name = '取消';break;
		case 0:name = '待付款';break;
		case 1:name = '待发货';break;
		case 2:name = '待收货';break;
		case 3:
		case 4:name = '完成';break;
	}
	return name;
}
function setInfo(){
	$('.gview .pic').loadbackground();
	{if !isset($integral_order)}$('.view .total strong, .price').priceFont('bigPrice');{/if}
}
function order_cancel(id){

}
$(function(){
	setInfo();
	$('.info .status font, .top').html(function(i, html){ return statusName(html) });
	$('.opr .im').click(function(){
		var member_id = $(this).attr('member_id');
		location.href = '/wap.php?app=chat&act=talk';
		return false;
	});
	$('a.pay').click(function(){
		if($.browser.wechat && $(this).attr('pay_method')!='wxpay' && $(this).attr('pay_method')!='wxpay_h5'){
			alert('在微信上只能使用微信支付\n该订单下单时使用了支付宝方式');
			return false;
		}
		$('.pay_form').submit();
	});
	$('a.cancel').click(function(){
		if(!confirm('真的要取消吗？'))return false;
		$('.cancel_form').submit();
	});
	$('a.refund').click(function(){
		location.href = 'wap.php?tpl=member.order_refund&order_id='+$(this).parent().parent().attr('mid')+'&total_price='+$(this).attr('total_price')+'&status='+$(this).attr('status');
	});
	$('a.ask').click(function(){
		$('.ask_form').submit();
	});
	$('a.delay').click(function(){
		if(!confirm('确定需要延迟收货吗？'))return false;
		$('.delay_form').submit();
	});
	$('a.ok').click(function(){
		if(!confirm('{if !isset($integral_order)}请收到货后，再确认收货！\n否则您可能钱货两空{else}确认收货吗？{/if}'))return false;
		$.postJSON('api.php?app=member&act=order_shouhuo', { id:$(this).parent().parent().attr('mid') }, function(json){
			if(json.error!=0){ $.overloadError(json.msg);return }
			location.href = location.href;
		});
	});
	$('a.again').click(function(){
		$.overload(null);
		var count = 0, breaker = false, data = $('.again_form textarea').val().formatJSON(), arr = [];
		if(!$.isArray(data))return false;
		for(var i=0; i<data.length; i++){
			(function(j){
				$.postJSON('api.php?app=cart&act=cart_total', { goods_id:data[j].goods_id, spec:data[j].spec }, function(json){
					if(breaker)return;
					if(json.error!=0){ $.overloadError(json.msg);breaker = true;return }
					if(json.data*1+1 > data[j].stocks){ $.overloadError('库存不足');breaker = true;return }
					var goods = { goods_id:data[j].goods_id, spec:data[j].spec, quantity:1 };
					arr.push(goods);
					count++;
					if(count == data.length){
						var val = { goods:arr };
						$('.goods').val($.jsonString(val));
						$('.again_form').submit();
					}
				});
			})(i);
		}
	});
	$('.order_cancel > span').click(function(){
		if(!confirm('确定需要取消订单吗？'))return false;
		var _thisId = $(this).attr('cancel_id');
		var _thisStatus = $(this).attr('status');
		if(!_thisId || _thisStatus != 1)return false;
		$.postJSON('api.php?app=member&act=order_cancel', { id:_thisId }, function(json){
			if(json.error!=0){
				$.overloadError(json.msg);
				return; 
			}else{
				location.reload();
			}
		});
	});
});
</script>
